package cn.supermarket.controller.monitor;

import cn.supermarket.common.annotation.Log;
import cn.supermarket.common.core.controller.BaseController;
import cn.supermarket.common.core.entity.Result;
import cn.supermarket.common.core.page.TableDataInfo;
import cn.supermarket.common.entity.system.SysOperLog;
import cn.supermarket.common.enums.BusinessType;
import cn.supermarket.common.utils.poi.ExcelUtil;
import cn.supermarket.system.dto.SysOperLogDTO;
import cn.supermarket.system.service.SysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author yp
 * @Date 2025/2/25:14:42
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperLogController extends BaseController {
    @Autowired
    private SysOperLogService operLogService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOperLogDTO operLog)
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLogDTO operLog)
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public Result remove(@PathVariable String[] operIds)
    {
        return toAjax(operLogService.removeById(operIds));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public Result clean()
    {
        operLogService.remove(null);
        return success();
    }
}
